<?php

/**
 * 交易所文章
 * @author thinkphper
 */
namespace app\common\redis;
use app\common\model\article\PublishArticleExchangeModel;
use app\common\model\article\PublishArticleModel;

class ExchangeRedis extends RedisModel {
	/**
	 * Redis配置名称
	 * @var string
	 */
	public $redis = 'default';
	
	/**
	 * Redis key
	 * @var string
	 */
	public $key = '';
	
	/**
	 * Redis key 前缀
	 */
	public $key_prefix = 'exchange_article';
	
	/**
	 * 创建交易所文章ID集合
	 * @param int $exchange_id 币种编号
	 * @param int $limit 数量限制 0 不限制
	 */
	public function createExchangeArticleList( $exchange_id, $limit=100 ) {
		// 获取交易所相关文章列表
		$modelArticle = new PublishArticleModel();
		$map = array(
				'is_published' => 1,
				'status' => 1,
				'deleted' => -1,
				'is_tmp' => -1,
		);
		
		$modelArtExchange = new PublishArticleExchangeModel();
		$ex_art_list = $modelArtExchange->get_exchange_article_list($exchange_id);
		$article_id_list = [];
		if ( $ex_art_list ) {
			$map['id'] = array('in', $ex_art_list);
			$article_id_list = $modelArticle->search_id_list($map, 1, false, 'create_time', $limit);
		}
		
		$this->SetRedisKey($exchange_id);
		if ( $this->ExistsKey() ) {
			$this->Delete();
		}
		if ($article_id_list) {
			
			$this->PipeStart();
			foreach ( $article_id_list as $item ) {
				if ( !$item ) {
					continue;
				}
				$this->ListRpush($item);
			}
			$this->PipeExec();
		}
	}
	
}